layui.use(['layer','table','form'], function(args){
    layer = layui.layer;
});

function add() {
    layer.prompt({
        formType: 0,
        title: '请输入模型名称',
    }, function(name, index, elem){
        layer.close(index);
        var loadIndex = layer.load(2);
        $.ajax({
            url: basePath+'process/model/add.do',
            data: {name: name},
            dataType: 'json',
            success: function (data, textStatus) {
                layer.close(loadIndex);
                layer.alert(data.message,function (index) {
                    layer.close(index);
                    if (data.success) {
                        window.open(basePath+'modeler/index.do?modelId='+data.data);
                        location.reload();
                    }
                });
            }
        });
    });
}
/**
 * 删除模型
 * @param id
 */
function delModel(id) {
    if (id) {
        var loadIndex = layer.load(2);
        $.ajax({
            url: 'model/delete.do',
            data: {id: id},
            dataType: 'json',
            success: function (data, textStatus) {
                layer.close(loadIndex);
                layer.alert(data.message,function (index) {
                    layer.close(index);
                    if (data.success) {
                        location.reload();
                    }
                });
            }
        });
    } else {
        layer.alert("id为空")
    }
}

/**
 * 发部/部署模型
 * @param id
 */
function deployModel(id) {
    if (id) {
        var loadIndex = layer.load(2);
        $.ajax({
            url: 'model/deploy.do',
            data: {id: id},
            dataType: 'json',
            success: function (data, textStatus) {
                layer.close(loadIndex);
                layer.alert(data.message,function (index) {
                    layer.close(index);
                    if (data.success) {
                        location.reload();
                    }
                });
            }
        });
    } else {
        layer.alert("id为空")
    }
}